import api from './request'
import type { ApiResponse } from './request'

/**
 * 分区管理API接口
 * @author Wu.Liang
 * @date 2025-01-30
 */

// 分区管理相关接口
export const zoneManagementApi = {
  /**
   * 获取分区管理页面初始数据
   * @param communityId 小区ID
   */
  getInitialData: (communityId: number) => 
    api.get<ApiResponse<any>>(`/api/region/zone-management/initial-data/${communityId}`),

  /**
   * 保存分区管理数据
   * @param data 保存数据
   */
  saveZoneData: (data: any) => 
    api.post<ApiResponse<void>>('/api/region/zone-management/save', data),

  /**
   * 判断小区进入状态
   * @param communityId 小区ID
   */
  determineEntryState: (communityId: number) => 
    api.get<ApiResponse<any>>(`/api/region/zone-management/entry-state/${communityId}`),

  /**
   * 创建新分区
   * @param data 分区数据
   */
  createZone: (data: any) => 
    api.post<ApiResponse<{
      id: number
      zoneName: string
      zoneCode: string
      communityId: number
      propertyCompanyId: number
      zoneType: string
      zoneColor: string
      zoneDescription?: string
      status: number
      createTime: string
      updateTime: string
    }>>('/api/region/zones', data),

  /**
   * 保存绘图数据
   * @param data 绘图数据
   */
  saveDrawingData: (data: any) => 
    api.post<ApiResponse<any>>('/api/region/zone-management/drawing', data),

  /**
   * 更新绘图数据
   * @param id 绘图数据ID
   * @param data 绘图数据
   */
  updateDrawingData: (id: number, data: any) => 
    api.put<ApiResponse<any>>(`/api/region/zone-management/drawing/${id}`, data),

  /**
   * 获取小区绘图数据
   * @param communityId 小区ID
   */
  getCommunityDrawingData: (communityId: number) => 
    api.get<ApiResponse<any>>(`/api/region/zone-management/drawing/community/${communityId}`)
}
